{% extends 'base.html' %}
{% block 'body' %}
<h1>Preferences</h1>

<form id="clear-links" method="post" action="{{ reverse_url('clear_links') }}">
	{{ xsrf_form_html() }}
	<button id="button" type="submit">Clear link history</button>
</form>

<form id="settings" method="post" action="{{ request.uri }}">
	{{ xsrf_form_html() }}
	<label for="default">Default page</label>
	<select id="default" name="default_page">
	{% for page in pages %}
		<option value="{{ page.id }}"{% if page.id == default %} selected{% end %}>{{ page.name }}</option>
	{% end %}
	</select>
	<noscript>
		<button type="submit">Save</button>
	</noscript>
</form>

<script>
var request = new Request({
	url: $('settings').action,
	link: 'chain'
});

$('default').addEvent('change', function() {
	$('settings').send();
});

$('clear-links').addEvent('submit', function(e) {
	e.preventDefault();
	$('button').disabled = true;
	this.send();
});
</script>
{% end %}